package com.cljz.makepassenger.ui.adapter;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.cljz.makepassenger.R;
import com.cljz.makepassenger.model.net.bean.InviteListBean;
import com.cljz.makepassenger.ui.holder.InviteListHolder;

import java.util.List;

import cn.droidlover.xdroidmvp.kit.Kits;


/**
 * Created by apple on 2017/3/24.
 */

public class InviteListAdapter extends RecyclerView.Adapter<InviteListHolder> {
    private Activity activity;
    private List<InviteListBean.DataBean> inviteList;

    public InviteListAdapter(Activity activity, List<InviteListBean.DataBean> inviteList) {
        this.activity = activity;
        this.inviteList = inviteList;
    }

    @Override
    public InviteListHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new InviteListHolder(LayoutInflater.from(activity).inflate(R.layout.item_inviter_list, parent, false), this);
    }

    @Override
    public void onBindViewHolder(InviteListHolder holder, int position) {
        holder.setData(inviteList, position);
        if (position == inviteList.size() - 1) {
            holder.itemView.setPadding(0, 0, 0, Kits.Dimens.dpToPxInt(activity, 30));
        } else {
            holder.itemView.setPadding(0, 0, 0, 0);
        }
    }

    @Override
    public int getItemCount() {
        return inviteList == null ? 0 : inviteList.size();
    }


    public void setData(List<InviteListBean.DataBean> data) {

        this.inviteList = data;
        notifyDataSetChanged();
    }

    public void addData(List<InviteListBean.DataBean> data) {
        int startPosition = this.inviteList.size() + 2;
        this.inviteList.addAll(data);
        notifyItemChanged(startPosition - 1); //刷新加载前最后一个item所设的padding值
        notifyItemRangeInserted(startPosition, data.size());

    }
}
